package com.bw.announcement

import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.bw.announcement.announcement.AnnouncementAdapter
import com.bw.announcement.announcement.AnnouncementViewModel
import com.bw.announcement.databinding.FragmentAnnouncementBinding
import com.bw.lib_base.base.BaseFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
@AndroidEntryPoint
class AnnouncementFragment() : BaseFragment<FragmentAnnouncementBinding,AnnouncementViewModel>() {
    override val mLayoutResId:Int
        get() = R.layout.fragment_announcement

    private var announcementAdapter = AnnouncementAdapter()


    override fun setupUI() {
        announcementAdapter = AnnouncementAdapter()
        binding.noticeRcy.apply {
            // 设置布局管理器为线性布局，垂直方向
            layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
            // 设置适配器
            adapter = announcementAdapter
        }

    }

    override fun fetchData() {
        vm.getAnnouncements(1,10)

    }

    override fun observeData() {
        lifecycleScope.launch {
            vm.announcementData.collect{
                if (it != null) {
                    // 设置适配器数据源
                    announcementAdapter.setList(it)
                }
            }
        }

    }

    override fun handleEvent() {

    }

    override fun lazyLoad() {
        fetchData()
    }


}